// 导入验证规则的包
const joi = require('joi')

// 定义登录注册的验证规则
const username = joi.string()
const password = joi.string().pattern(/^[\S]{6,12}$/).required()
const role_id = joi.number()
const code = joi.string()

// 定义修改用户信息的验证规则
const name = joi.string()
const age = joi.number()
const sex = joi.string()
const phone = joi.string().pattern(/^1[3-9]\d{9}$/)
const photo = joi.string().dataUri()

// 定义修改医生信息的验证规则
const feat = joi.string()
const address = joi.string()
const specialty = joi.number()

// 定义验登录表单的规则对象
exports.reg_login_schema = {
    body: {
        username,
        password,
        code
    }
}
// 定义验证注表单的规则对象
exports.reg_register_schema = {
    body: {
        username,
        password,
        password2: joi.ref('password'),
        role_id,
        name,
        age,
        sex,
        phone,
        photo,
        address,
        specialty
    }
}
// 定义更新用户和医生基本信息表单的规则对象
exports.reg_update_user_schema = {
    body: {
        name,
        age,
        sex,
        phone,
        photo,
        feat,
        address,
        specialty
    }
}

// 定义修改密码的表单验证规则
exports.reg_pwd_schema = {
    body: {
        oldPwd: password,
        newPwd: joi.not(joi.ref('oldPwd')).concat(password)
    }
}